package com.demo.d513;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component("audience")
@Aspect
public class Audience {

	@Pointcut("execution(* com.demo.d514.Performer.perform(..))")
	public void performance() {
	}

	@Before("performance()")
	public void takeSeats() {
		System.out.println("The audience is taking seats! watch ");
	}

	@Before("performance()")
	public void turnOffPhones() {
		System.out.println("The audience is turning off phones!");
	}

	@After("performance()")
	public void applaud() {
		System.out.println("CLAP!  CLAP!  CLAP!");
	}

	@AfterReturning("performance()")
	public void leave() {
		System.out.println("The audience is leaving!");
	}

	public void demandRefund() {
		System.out.println("Boo!");
	}

	@Around("performance()")
	public void watchPerformance(ProceedingJoinPoint joinPoint) {
		System.out.println("watch performance :");
		try {
			long start = System.currentTimeMillis();
			joinPoint.proceed();
			long end = System.currentTimeMillis();
			System.out.println("take time:" + (end - start));
		} catch (Throwable e) {
			System.out.println("Boo! watch");
		}
		System.out.println("after watch performance!");

	}

}
